$(function () {
    var result = Model.goods.findAllGoodsItem()
    model(result);

    $(document).on('mousedown', '.del-product-btn', function () {
        var id = $(this).attr('goods-id');
        var confirms = weui.confirm(
            "真的要删除该拍品吗？",
            function () {
                // 删除拍品
                var result = Model.user.delGoods({
                    goodsId: id,
                });
                if (result.code) {
                    location.reload();
                    return false;
                }
                location.reload();
            },
            function () {
            }
        );
    });
})

function model(result) {
    var gridColumns_2_2_2 = [
        {
            id: 'content',
            title: '商品名称',
            type: 'string',
            columnClass: 'text-center',
            fastQuery: true,
            fastQueryType: 'eq'
        },
        {
            id: 'description',
            title: '详情',
            type: 'string',
            columnClass: 'text-center',
            fastQuery: true,
            fastQueryType: 'eq'
        },
        {
            id: 'price',
            title: '价格',
            type: 'string',
            columnClass: 'text-center',
            fastQuery: true,
            fastQueryType: 'eq'
        },
        {
            id: 'stock',
            title: '库存',
            type: 'string',
            columnClass: 'text-center',
            fastQuery: true,
            fastQueryType: 'eq'
        },
        {
            id: 'id',
            title: '操作',
            type: 'string',
            columnClass: 'text-center',
            fastQuery: true,
            fastQueryType: 'eq', resolution: function (value, record, column, grid, dataNo,
                                                       columnNo) {
                var htmlTmpl = '<div><a href="javascript:;" class="btn btn-success del-product-btn" goods-id="' +record['id'] + '">删除</a></div>';
                return htmlTmpl;
            }

        }

    ];
    var gridOption_2_2_2 = {
        lang: 'zh-cn',
        ajaxLoad: false,
        loadAll: true,
        datas: result.data,
        columns: gridColumns_2_2_2,
        gridContainer: 'gridContainer_2_2_2',
        toolbarContainer: 'gridToolBarContainer_2_2_2',
        tools: '',
        pageSize: 5,
        pageSizeLimit: [1, 10, 20, 50]
    };
    var grid_2_2_2 = $.fn.dlshouwen.grid.init(gridOption_2_2_2);
    grid_2_2_2.load();
}
